package com.augmentum.oes.dao.impl;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.augmentum.oes.dao.UserDao;
import com.augmentum.oes.model.User;
import com.augmentum.oes.util.StringUtil;

@Repository
public class UserDaoImpl extends BaseDaoImpl implements UserDao {

    private static final String MODEL_CLASS_NAME = User.class.getName();
    private static final String GET_BY_USER_NAME = ".getByUserName";
    private static final String GET_BY_ID = ".getById";
    private static final String UPDATE = ".update";
    @Resource
    private SqlSession sqlSession;

    public UserDaoImpl() {
        super();
    }

    @Override
    public User getByUserName(String userName) {
        if (StringUtil.isEmpty(userName)) {
            return null;
        }
        return sqlSession.selectOne(MODEL_CLASS_NAME + GET_BY_USER_NAME, userName);
    }

    @Override
    public User getById(int id) {
        if (id <= 0) {
            return null;
        }
        return sqlSession.selectOne(MODEL_CLASS_NAME + GET_BY_ID, id);
    }

    @Override
    public void update(User user) {
        sqlSession.update(MODEL_CLASS_NAME + UPDATE, user);
    }

}
